package cn.zz.veggie.web.controller.mgmt;

import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.zz.comm.core.types.query.PageQuery;
import cn.zz.comm.types.result.P;
import cn.zz.comm.web.annotation.BoxRespResult;
import cn.zz.veggie.application.service.PurchaseAppService;
import cn.zz.veggie.web.types.dto.mgmt.purchase.MgmtPurchaseCreateDto;
import cn.zz.veggie.web.types.dto.mgmt.purchase.MgmtPurchaseQueryDto;
import cn.zz.veggie.web.types.vo.mgmt.purchase.MgmtPurchaseVo;
import jakarta.validation.constraints.Positive;
import lombok.RequiredArgsConstructor;

/**
 * @author zhongq
 * @since 2024/6/8
 */
@Validated
@BoxRespResult
@RestController
@RequiredArgsConstructor
@RequestMapping("/mgmt/purchase")
public class MgmtPurchaseController {

	private final PurchaseAppService purchaseAppService;

	/**
	 * 结算列表
	 */
	@GetMapping("/list")
	public P<MgmtPurchaseVo> list(@Validated MgmtPurchaseQueryDto dto,
			@RequestParam(defaultValue = "1") @Positive Integer current,
			@RequestParam(defaultValue = "10") @Positive Integer size) {
		return purchaseAppService.adminGetList(dto, PageQuery.of(current, size));
	}

	/**
	 * 刷新统计
	 */
	@PutMapping("/refresh")
	public void refresh(@RequestParam @Positive Integer id) {
		purchaseAppService.adminRefresh(id);
	}

	/**
	 * 创建 采购统计
	 */
	@PostMapping("/create")
	public void create(@RequestBody @Validated MgmtPurchaseCreateDto dto) {
		dto.requireValid();
		purchaseAppService.mgmtCreatePurchase(dto);
	}

	/**
	 * 删除 采购统计
	 */
	@DeleteMapping("/remove")
	public void create(@RequestParam @Positive Integer id) {
		purchaseAppService.mgmtRemovePurchase(id);
	}

}